<template>
	<view class="counter">
		<view class="counter-button" @click.stop="numberChange('reduce')"></view>
		<input class="counter-number" type="number" v-model="number" :disabled="true" />
		<view class="counter-button" @click.stop="numberChange('add')"></view>
	</view>
</template>

<script>
	export default {
		name:"counter",
		data() {
			return {
				number: 1
			};
		},
		methods: {
			numberChange(mode) {
				if (mode == 'reduce') {
					if (this.number != 1) this.number--
				}
				if (mode == 'add') {
					this.number++
				}
				this.$emit('change', this.number)
			}
		}
	}
</script>

<style scoped>
	.counter {
		display: flex;
		flex-direction: row;
		align-items: center;
	}
	
	.counter-button {
		width: 14px;
		height: 14px;
		border-radius: 7px;
		box-sizing: border-box;
		border: 1px solid #1890ff;
		position: relative;
		display: flex;
		align-items: center;
		justify-content: center;
	}
	
	.counter-number {
		font-size: calc(var(--base) * 12);
		line-height: calc(var(--base) * 12);
		padding: 4px 8px;
		width: 20px;
		text-align: center;
		color: #333;
	}
	
	.counter-button:first-child::before {
		content: '';
		width: 8px;
		height: 2px;
		background: #1890ff;
	}
	
	.counter-button:last-child {
		background: #1890ff;
	}
	
	.counter-button:last-child::before {
		content: '';
		width: 8px;
		height: 2px;
		background: #fff;
	}
	
	.counter-button:last-child::after {
		content: '';
		width: 2px;
		height: 8px;
		background: #fff;
		position: absolute;
		top: 50%;
		left: 50%;
		transform: translate(-50%, -50%);
	}
</style>